/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package admin.beans;

import abstractClasses.AbstractFilterableEntityList;
import entities.Company;
import facades.CandidateFacade;
import facades.CompanyFacade;
import java.io.Serializable;
import javax.enterprise.context.SessionScoped;
import javax.enterprise.event.Event;
import javax.faces.model.SelectItem;
import javax.inject.Inject;
import javax.inject.Named;
import qualifiers.EditedEntityEvent;
import qualifiers.PreEditEntityEvent;
import qualifiers.PreRemoveEntityEvent;
import qualifiers.RemovedEntityEvent;

/**
 *
 * @author Alvaro
 */
@Named(value = "adminCompanyBean")
@SessionScoped
public class AdminCompanyBean extends AbstractFilterableEntityList<Company, CompanyFacade> implements Serializable {

    @Inject
    @PreRemoveEntityEvent
    private Event<Company> preRemoveCompanyEvent;
    @Inject
    @RemovedEntityEvent
    private Event<Company> removeCompanyEvent;
    @Inject
    @PreEditEntityEvent
    private Event<Company> preEditCompanyEvent;
    @Inject
    @EditedEntityEvent
    private Event<Company> editedCompanyEvent;
    @Inject
    private CompanyFacade companyFacade;
    @Inject
    private CandidateFacade candidateFacade;
    /**
     * Creates a new instance of AdminCompanyBean
     */
    public AdminCompanyBean() {
    }

    @Override
    public String redirectToViewEntity() {
        return null;
    }
    
    public SelectItem[] getTrueFalseOptions() {
        SelectItem[] options = new SelectItem[3];  
        options[0] = new SelectItem("", "Indiferente");
        options[1] = new SelectItem(Boolean.TRUE.toString(), "Sí");
        options[2] = new SelectItem(Boolean.FALSE.toString(), "No");
        return options;  
    }
    
    public void removeCompany(){
        preRemoveCompanyEvent.fire(getChosenEntity());
        companyFacade.remove(getChosenEntity());
        removeCompanyEvent.fire(getChosenEntity());
    }
    
    public void editCompany(){
        preEditCompanyEvent.fire(getChosenEntity());
        companyFacade.edit(getChosenEntity());
        editedCompanyEvent.fire(getChosenEntity());
    }
    
    public Integer getNumRelatedUserFromUser(Company company){
        return candidateFacade.relatedUserFromCompany(company);
    }
}
